Skip to content

fix: expose refreshAiGatewayVirtualKey for stale key recovery#270

Merged
dimavedenyapin merged 3 commits intomainfrom
task/byxne5aiqk69hrdlpc7vrk9h
Apr 27, 2026
Merged

fix: expose refreshAiGatewayVirtualKey for stale key recovery#270
dimavedenyapin merged 3 commits intomainfrom
task/byxne5aiqk69hrdlpc7vrk9h

Conversation

@dimavedenyapin
Copy link
Copy Markdown
Contributor

@dimavedenyapin dimavedenyapin commented Apr 27, 2026

Summary

Fixes "Invalid proxy server token" auth errors when an admin rotates a user's AI gateway virtual key (removes and re-assigns a plan). Three changes work together:

  • Expose refreshAiGatewayVirtualKey() on EnterpriseAuth so callers can trigger a key refresh on demand
  • Refresh the key before each agent sessionAgentManager.startAdapterSession() calls the refresh so the local SQLite cache always has the latest key from the backend
  • Push refreshed config to a running OpenCode servercreateSession() now calls pushMergedConfigToClient() after ensureServerRunning(), because ensureServerRunning early-returns when the server is already up, skipping the config push that bakes provider credentials

Related PR

Test plan

  • Remove AI gateway plan for a user, then re-assign it
  • Verify the 20x desktop app picks up the new key on next session start (no "Invalid proxy server token" error)
  • Verify existing sessions continue to work when the key hasn't changed (no unnecessary restarts)

🤖 Generated with Claude Code

dimavedenyapin and others added 3 commits April 27, 2026 14:19
Add refreshAiGatewayVirtualKey() to EnterpriseAuth so callers (IPC
handlers, adapter error recovery) can trigger a key refresh when
LiteLLM returns "Invalid proxy server token" during a session.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
When an admin rotates the user's virtual key (via plan removal + re-
assignment), the desktop's local SQLite cache still holds the old key.
Now the agent-manager calls refreshAiGatewayVirtualKey() before each
session start so the adapter always builds its provider config with the
latest key from the backend. Best-effort — falls back to the cached key
if the refresh fails (offline, server down).

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ensureServerRunning() early-returns when the server is already running at
the target URL, which skips the initial config push. This means rotated
provider credentials (e.g. a new LiteLLM virtual key after plan re-
assignment) never reach the running server. Now createSession() always
calls pushMergedConfigToClient() after ensureServerRunning(), so the
OpenCode provider config reflects the latest key fetched by
refreshAiGatewayVirtualKey() in agent-manager.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@dimavedenyapin dimavedenyapin merged commit 76c6eb0 into main Apr 27, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant